package com.wdy.golden.tinysql.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class TinysqlSpringUtil implements ApplicationContextAware {
	private static ApplicationContext ac = null; 
	
	private static TinysqlSpringUtil tinysqlSpringUtil;
	
	@SuppressWarnings("static-access")
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		tinysqlSpringUtil= this;
		tinysqlSpringUtil.ac = applicationContext;  
	}

    @SuppressWarnings("static-access")
	public static Object getBean(String beanName) {  
        return tinysqlSpringUtil.ac.getBean(beanName);  
    } 
	
	@SuppressWarnings("static-access")
	public static <T> T getBean(String beanName, Class<T> clazz){
		return tinysqlSpringUtil.ac.getBean(beanName,clazz);
	}
}
